﻿'use strict';
/*userAccountInfoCtrl  Controllers */
//账户信息
app.controller('userAccountInfoCtrl', ['$scope', '$http', "$state", '$stateParams', '$location', '$ngBootbox', 'dataService', 'valueservice', 'exceptionHandleService',
    function ($scope, $http, $state, $stateParams, $location, $ngBootbox, dataService, valueservice, exceptionHandleService) {
        if ($stateParams.id != null) {
            window.localStorage.id = $stateParams.id;
        }
        if ($stateParams.carNumber !== null) {
            window.localStorage.carCode = $stateParams.carNumber;
        }
        $scope.userId = $stateParams.id || window.localStorage.id;
        $scope.enableUserInfo = true;
        $scope.carriercategoryList = valueservice.getCarriageType();
        $scope.carLengthList = valueservice.getCarLength().slice(1);
        $scope.cartypeList = valueservice.getCarType().slice(1);
        dataService.GetUserBasicInfo($scope.userId)
        //$http.get(Mustache.render("/api/" + "User/GetUserBasicInfo?userId={{userId}}", { userId: $scope.userId }))
        .then(function (res) {
            //console.info(res);
            res = res.data.info;
            $scope.driverPhone = res.phoneNumber;
            $scope.carCode = res.carNumber;
            $scope.driver = res.realName;
            $scope.carType = res.carType; 
            $scope.carLength = res.carLength;
            $scope.bearing = parseFloat(res.authorizedLoad.toFixed(4));
            $scope.carrierCategory = res.carriageType;
            $scope.address = res.address;
            $scope.message = res.profile;
            //----
            $scope.headImage = res.headImage;
            $scope.point = res.point;
            $scope.realNameState = res.realNameState;
            $scope.userName = res.userName;
        }, function (er) {
        });
        $scope.carSave = function () {
            $scope.enableUserInfo = true;
            var list = {
                Address: $scope.address,
                AuthorizedLoad: $scope.bearing,
                CarLength: $scope.carLength,
                CarNumber: $scope.carCode,
                CarriageType: $scope.carrierCategory,
                CarType: $scope.carType,
                HeadImage: $scope.headImage,
                PhoneNumber: $scope.driverPhone,
                Point: $scope.point,
                //     简介
                Profile: $scope.message,
                RealName: $scope.driver,
                RealNameState: $scope.realNameState,
                UserId: $scope.userId,
                UserName: $scope.userName,
            }
            dataService.ModifyUserInfoByUserId($scope.userId, true, list)
            //$http.post(Mustache.render("/api/" + "User/ModifyUserInfoByUserId?userId={{userId}}&forceEdit={{forceEdit}}", { userId: $scope.userId, forceEdit:true }), {
            //    Address: $scope.address,
            //    AuthorizedLoad: $scope.bearing,
            //    CarLength: $scope.carLength,
            //    CarNumber: $scope.carCode,
            //    CarriageType: $scope.carrierCategory,
            //    CarType: $scope.carType,
            //    HeadImage: $scope.headImage,
            //    PhoneNumber: $scope.driverPhone,
            //    Point: $scope.point,
            //    //     简介
            //    Profile: $scope.message,
            //    RealName: $scope.driver,
            //    RealNameState: $scope.realNameState,
            //    UserId: $scope.userId,
            //    UserName: $scope.userName,
            //})
            .then(function (res) {
            })
        }
    }]);



